class_name CircleBtnMenu
extends BaseView

#region 属性
@export var btn_amount:int = 8
@export var slot_btn_scene:PackedScene
var _slot_btns:Array[SlotBtn] = []
var func_get_icon:Callable
var func_get_desc:Callable
var func_is_selected:Callable
#endregion
#region 字段
#endregion
#region 信号
signal btn_pressed(idx:int)
#endregion

#region 基类方法
#endregion
#region 公共方法
func init(func_get_icon:Callable = Callable(),func_get_desc:Callable = Callable(),func_is_selected:Callable = Callable(), btn_amount:int = 8):
	self.func_get_icon = func_get_icon
	self.func_get_desc = func_get_desc
	self.func_is_selected = func_is_selected
	self.btn_amount = btn_amount
	for i in range(8):
		var slot_btn:SlotBtn = slot_btn_scene.instantiate()
		%SlotBtns.add_child(slot_btn)
		slot_btn.init_slot_btn(self,i)
		slot_btn.visible = i < self.btn_amount
		_slot_btns.append(slot_btn)
	update_desc()
	update_slot_btns()
func change_btn_amount(new_btn_amount:int):
	btn_amount = new_btn_amount
	update_slot_btns()
func update_slot_btns():
	for idx in btn_amount:
		# 第0个是Center，排除一下
		var slot_btn:SlotBtn = %SlotBtns.get_child(idx + 1)
		slot_btn.visible = func_get_icon.is_valid() and func_get_icon.call(idx)
		if slot_btn.visible:
			slot_btn.set_icon(func_get_icon.call(idx + 1))
		if func_is_selected.is_valid():
			var is_selected:bool = func_is_selected.call(idx)
			slot_btn.set_selected(is_selected)
			if func_is_selected and func_get_desc.is_valid():
				update_desc(func_get_desc.call(idx))
func update_desc(desc:String = ""):
	%DescLabel.text = desc
#endregion
#region 私有方法
#endregion
#region 生命周期函数
func _ready() -> void:
	init()
#endregion
